<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">

    </el-form>

    <el-row :gutter="10" class="mb8">

    </el-row>

    <el-table v-loading="loading" :data="feedbackList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="会员" align="center" prop="memberMobile" />
      <el-table-column label="反馈类型" align="center" prop="type" :formatter="typeFormat" />
      <el-table-column label="内容" align="center" prop="content" />
      <el-table-column label="图片" align="center" prop="imgs" >
        <template slot-scope="scope">
          <el-image v-for="img in scope.row.imgList " :src="img" :preview-src-list="scope.row.imgList" style="width: 100px; margin-left: 5px" @click.stop="handleClickItem"></el-image>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="gmtTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gmtTime) }}</span>
        </template>
      </el-table-column>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listFeedback } from "@/api/cms/feedback";
import defaultSettings from '@/settings'
export default {
  name: "Feedback",
  data() {
    return {
      ossPreview: defaultSettings.ossPreview,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 会员反馈表格数据
      feedbackList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 反馈类型字典
      typeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        memberId: undefined,
        content: undefined,
        imgs: undefined,
        gmtTime: undefined,
        type: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("feedback_type").then(response => {
      this.typeOptions = response.data;
    });
  },
  methods: {
    /** 查询会员反馈列表 */
    getList() {
      this.loading = true;
      listFeedback(this.queryParams).then(response => {
        this.feedbackList = response.rows;
        if (this.feedbackList.length > 0){
          this.feedbackList.forEach(item => {
            if (item.imgs){
              let imgStrArr = item.imgs.split(',');
              let imgArr = []
              for (var i = 0 ;i< imgStrArr.length ; i++){
                let fillImg = this.ossPreview + imgStrArr[i];
                imgArr.push(fillImg)
              }
              item.imgList = imgArr;
            }
          })
        }
        this.total = response.total;
        this.loading = false;
      });
    },
    // 反馈类型字典翻译
    typeFormat(row, column) {
      return this.selectDictLabel(this.typeOptions, row.type);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        memberId: undefined,
        content: undefined,
        imgs: undefined,
        gmtTime: undefined,
        type: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },

    handleClickItem(){
      // 获取遮罩层dom

      this.$nextTick(() => {
        console.log("111111111111111111111111")
        let domImageMask = document.querySelector(".el-image-viewer__mask");
        if (!domImageMask) {
          console.log("2222222222222222222222")
          return;
        }
        domImageMask.addEventListener("click", () => {
          // 点击遮罩层时调用关闭按钮的 click 事件
          document.querySelector(".el-image-viewer__close").click();
        });
      })

    }
  }
};
</script>
